package com.lingxu.module.collection.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lingxu.base.common.api.vo.Result;
import com.lingxu.base.system.manage.vo.LoginUser;
import com.lingxu.module.collection.entity.*;
import com.lingxu.module.collection.service.ICountAnalysisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@Api(tags="统计分析-模型分析")
@RestController
@RequestMapping("/countAnalysis")
public class CountAnalysisController {

    @Resource
    private ICountAnalysisService countAnalysisService;

    @ApiOperation(value="统计分析-模型分析程序处理", notes="统计分析-模型分析程序处理")
    @PostMapping(value = "/handelModelAnalysis")
    public Result<?> handelModelAnalysis() {
        countAnalysisService.handelModelAnalysis();
        return Result.ok("分析完成");
    }

    @ApiOperation(value="统计分析-模型分析", notes="统计分析-模型分析")
    @PostMapping(value = "/getModelAnalysisPageList")
    public Result<?> getModelAnalysisPageList(@RequestBody ModelAnalysisSearchVo vo) {
        LoginUser user =  (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String region= user.getRegion();
        if(StringUtils.isBlank(region)){
            region="320000";
        }
        if(StringUtils.isBlank(vo.getCreateregion())){
            vo.setCreateregion(region);
        }
        Page<ModelAnalysis> page = new Page<ModelAnalysis>(vo.getPageNo(), vo.getPageSize());
        IPage<ModelAnalysis> pageList = countAnalysisService.getModelAnalysisPageList(page,vo);
        return Result.ok(pageList);
    }

}
